/*
 * Copyright (c) 2010 CCX(China) Co.,Ltd. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * CCX(China) Co.,Ltd. ("Confidential Information").
 * It may not be copied or reproduced in any manner without the express 
 * written permission of CCX(China) Co.,Ltd.
 *
 * Author: Wangyaoxi
 * Date: 2010-4-16 下午04:00:02
 */
package com.ccxe.manage.service.impl;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 页面交互业务类 基础父类
 * 
 * @author wyx
 * 
 */
public abstract class BaseRequestService {
	protected HttpServletRequest request;
	protected HttpServletResponse response;
	/**
	 * 处理业务
	 */
	public void dealWithBusiness() {
	
			//request.setCharacterEncoding("UTF-8");
			// 处理接传值
			this.buildParameters();
			// 跳转页面
			this.forwardToJsp();
	
	}

	/**
	 * 处理接传值
	 */
	public abstract void buildParameters();

	/**
	 * 页面跳转
	 */
	public void forwardToJsp() {
		try {
			// 获取页面路径
			String url = buildJspUrl();
			if (validUrl(url)) {
				request.getRequestDispatcher(url).forward(request, response);
			}
		} catch (ServletException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	private boolean validUrl(String url) {
		return !(url == null || "".equals(url) || "".equals(url.trim()));
	}

	/**
	 * 获取页面路径
	 * 
	 * @return
	 */
	protected abstract String buildJspUrl();
}
